
/**
 *头条支付的通用交易方法
 */

// 通用订单获取
const getOrderTtMess = (mess) => {
  return new Promise((resolve, reject) => {
    let { data, byteAuthorization} = mess
    tt.requestOrder({
      data,
      byteAuthorization,
      success(res) {
        console.log(res)
        resolve(res)
      },
      fail(err) {
        console.log('订单失败的回调', err)
      }
    })
  })
}
// 拉起通用支付面板
const intoPayPage = (objMess) => {
  return new Promise((resolve, reject) => {
    let {
      orderId,
      imId
    } = objMess

    console.log('orderId', orderId, imId)
    tt.getOrderPayment({
      orderId: orderId,
      imId: imId || undefined,
      success(res) {
        resolve(res)
      },
      fail(err) {
        console.log('支付失败的回调', err)
      }
    })
  })
}

// 获取宿主小程序
const getLittleAppNowObj = () => {
  return new Promise((resolve, reject) => {
    tt.getSystemInfo({
      success: (res) => {
        if (res && res.version) {
          resolve(res)
        } else {
          resolve('')
        }
      },
      fail: () => {
        resolve('')
      }
    })
  })
}

export {
  getOrderTtMess,
  intoPayPage,
  getLittleAppNowObj
}